package com.dhcc.android.base.gis;

import android.graphics.Bitmap;
import android.graphics.PointF;
import android.view.MotionEvent;
import android.view.View;

import srs.GPS.GPSConvert;
import srs.Geometry.IPoint;
import srs.tools.BaseControl;
import srs.tools.BaseTool;

/**
 * @author 目标对象的点选
 * @author lzy
 *
 */
public class TouchLongToolForPointOnly extends BaseTool {
	private static String mTitleStr = "详细信息";
	/**
	 * MapControl输出的底图
	 * 
	 */
	Bitmap mBitExMap = null;

	/**
	 * 在此添加点击地图后会触发的效果；
	 * 
	 */
	public SelectItemChangedListener zoom2Selected = null;

	@Override
	public String getText() {
		return mTitleStr;
	}

	@Override
	public Bitmap getBitmap() {
		return null;
	}

	public BaseControl getBuddyControl() {
		return this.mBuddyControl;
	}

	public void setBuddyControl(BaseControl value) {
		if (value != null) {
			this.mBuddyControl = value;
			mBuddyControl.getActiveView().FocusMap().getSelectionSet()
					.ClearSelection();
		}
	}

	@Override
	public void onClick(View v) {
		try {
			super.onClick(v);
			mEnable = true;
			mBuddyControl.setDrawTool(this);
			mBuddyControl.PartialRefresh();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Override
	public boolean onTouch(View v, MotionEvent event) {
		switch (event.getAction()) {
		case MotionEvent.ACTION_DOWN:
			mBitExMap = mBuddyControl.getActiveView().FocusMap()
					.ExportMap(false);
			break;
		case MotionEvent.ACTION_UP:
			try {
				if (event.getPointerCount() == 1) {
					super.onTouch(v, event);
					PointF pF = new PointF(event.getX() * mRate, event.getY()
							* mRate);
					IPoint selGeo = mBuddyControl.ToWorldPoint(
							new PointF(pF.x,pF.y));
					/*
					 * 重点：
					 * ******保存点击的位置，lonlat就是你需要的经纬度信息********， 
					 * edit by 李忠义
					 * 20150629
					 */
					double[] lonlat = GPSConvert.PROJECT2GEO(selGeo.X(),
							selGeo.Y(), mBuddyControl.getActiveView()
									.FocusMap().getGeoProjectType());

					if (zoom2Selected != null) {
						/* 点选时触发的事件 */
						zoom2Selected.doEventSettingsChanged(lonlat);
					}
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
			break;
		}
		return false;
	}
}
